package com.arithmetic.version2;

import org.junit.Test;
import static org.junit.Assert.*;

public class ExerciseTester {

    @Test
    public void testConstructor() {
        Exercise exercise = new Exercise();
        assertNotNull(exercise);
        assertEquals(0, exercise.size());
    }

    @Test
    public void testGenerateAdditionExercise() {
        Exercise exercise = new Exercise();
        exercise.generateAdditionExercise(5);

        assertEquals(5, exercise.size());

        // 验证所有题目都是加法
        for (BinaryOperation op : exercise) {
            assertEquals('+', op.getOperator());
        }
    }

    @Test
    public void testGenerateSubstractExercise() {
        Exercise exercise = new Exercise();
        exercise.generateSubstractExercise(5);

        assertEquals(5, exercise.size());

        // 验证所有题目都是减法
        for (BinaryOperation op : exercise) {
            assertEquals('-', op.getOperator());
        }
    }

    @Test
    public void testGenerateBinaryExercise() {
        Exercise exercise = new Exercise();
        exercise.generateBinaryExercise(10);

        assertEquals(10, exercise.size());

        // 验证包含加法和减法
        boolean hasAddition = false;
        boolean hasSubstraction = false;

        for (BinaryOperation op : exercise) {
            if (op.getOperator() == '+') {
                hasAddition = true;
            } else if (op.getOperator() == '-') {
                hasSubstraction = true;
            }
        }

        assertTrue("应该包含加法", hasAddition);
        assertTrue("应该包含减法", hasSubstraction);
    }

    @Test
    public void testNoDuplicateOperations() {
        Exercise exercise = new Exercise();
        exercise.generateAdditionExercise(5);

        // 简单验证数量正确即可
        assertEquals(5, exercise.size());
    }
}